import flash.events.Event;
import flash.filesystem.File;

import tech.moya.flexbase.beans.Connection;
import tech.moya.flexbase.core.BaseContext;
import tech.moya.flexbase.core.ui.ApplicationContext;
import tech.moya.flexbase.dao.TableDAO;
import tech.moya.flexbase.components.QueryPanel;
import mx.events.IndexChangedEvent;

public function onAddConnectionClicked(event:Event):void{
	
	var file:File = new File();
	file.addEventListener(Event.SELECT,onDBFileSelected);
	file.browseForOpen("Choose a database File");
	
}

public function onDBFileSelected(event:Event):void{
	var file:File = (File(event.target));
	var bcontext:BaseContext = ApplicationContext.getCurrentApplicationContext().openQueryPanel(file.nativePath);
	var tableDAO:TableDAO = new TableDAO(bcontext);
	var connection:Connection = new Connection(tableDAO.getAllTables(),file.name,file.nativePath);
	ApplicationContext.getCurrentApplicationContext().addConn2TreeMenu(connection);
}

public function onSelectedTabChanged(event:Event):void{
	trace(IndexChangedEvent(event).relatedObject);
	ApplicationContext.getCurrentApplicationContext().changeQueryPanel(QueryPanel(IndexChangedEvent(event).relatedObject));
}